/*
 *	search-view view
 *  -----------------------------------------------------------------------------------------------------------
 */

site.view('desktop-embed-view', {

	elementId: 'desktop-embed-modal',
	parent: 'desktop-view',

	onLoad: function(settings) {
		if(!this.loaded) {
			var that = this;	
		
			this.request({
				
				url: '/project/get_embed_object',
				type: 'post',
				dataType: 'json',
				data: {
					link: settings.link
				},

				success: function(data) {

					that.projectViewHtml = that.createElement('div');
					that.projectViewHtml.setAttribute('id', that.elementId);
					that.projectViewHtml.setAttribute('style', 'display: none;');	
					that.projectViewHtml.innerHTML = data.content;

					that.startAll(that.projectViewHtml, settings);
				}
			});
		}
	},
	
	onUnload: function() {
		this.stopAll();
	}

})

.module('main', function(context) {
	var query = context.query,
		container,
		overlay;

	return {
		init: function(element, settings) {
			
			container = query(element);
			query('body').append(element);
			container.fadeIn('normal');

			// Overlay
			var that = context.query(this);    
			overlay = context.query('#add-element-msg-prompt').overlay({
				top: 'center',
				mask: {color: '#000', loadSpeed: 400, opacity: 0.5},
				closeOnClick: true,
				load: true,
				onClose: function() {
					context.query('#add-element-msg-prompt').remove();
					context.closeView();
				}
			});

			query('#overlay_item_cancel').click( function() {
				context.closeView();					
			});
		},

		destroy: function() {
			
			if(overlay.overlay().isOpened) {
				overlay.overlay().close();
			}
			
			container.html('');
			container.remove();
		}
	}
});